angular.module('mamApp').controller('addLabelController', ['$scope', 'ContractManagementManager', '$state', '$uibModal','ImsDialog','$uibModalInstance','CPExamineManager','param',
    function ($scope, ContractManagementManager, $state, $uibModal,ImsDialog,$uibModalInstance,CPExamineManager,param) {
    $scope.total = 0;
    $scope.red=false;
    $scope.table = JSON.parse(localStorage.getItem("codeTable"));
    $scope.Ok = function () {
        $uibModalInstance.close($scope.data);
    };
    $scope.cancel = function () {
        $uibModalInstance.dismiss("cancel");
    };

    CPExamineManager.addLabel().then(function (result) {
        $scope.labelList=result.data.pageList;
        console.log(param)
            param.labelChecked.forEach(function(labelChecked){
                $scope.labelList.forEach(function(label){
                    if( label.list){
                        label.list.forEach(function(tag){
                            if(tag.anchorId==labelChecked.anchorId){
                                tag.checked=true;

                            }

                        })
                    }

                })
            })

    })

    $scope.anchortag=function(){
        $scope.selectIds()
    }

    $scope.selectIds = function () {
        var ids=[];
       $scope.labelList.forEach(function(label){
           if( label.list){
               label.list.forEach(function(tag){
                   if(tag.checked){
                       ids.push(tag)

                   }

               })
           }
           if(ids.length>5){
               $scope.red=true;
           }else {
               $scope.red=false;
           }
       })
        return ids;

    }
        if( $scope.red==false){
            console.log(123)
            $scope.modelOk = function ($event, item) {
                $uibModalInstance.close($scope.selectIds());
            };
        }else {

        }


    $scope.modelCancel = function () {
        $uibModalInstance.dismiss("cancel");
    };


}])

